package com.baowenli.server;


import com.baowenli.mapper.HouseInfoMapper;
import com.baowenli.mapper.OfficalInfoMapper;
import com.baowenli.pojo.OrderType;
import com.baowenli.pojo.Room;
import com.baowenli.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class HousrInfoService {
    SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();

    /**
     * 查询所有
     *
     * @return
     */
    public List<Room> selectAllHouseInfo() {
        //2.获取sqlSession
        SqlSession sqlSession = factory.openSession();
        //3.获取BrandMapper
        HouseInfoMapper mapper = sqlSession.getMapper(HouseInfoMapper.class);
        //4.调用方法
        List<Room> rooms = mapper.selectAllHouseInfo();
        sqlSession.commit();
        sqlSession.close();
        return rooms;
    }

    /**
     * 通过id查找房间价钱
     *
     * @return
     */
    public Room selectByIdToPrice(int id) {
        //2.获取sqlSession
        SqlSession sqlSession = factory.openSession();
        //3.获取BrandMapper
        HouseInfoMapper mapper = sqlSession.getMapper(HouseInfoMapper.class);
        //4.调用方法
        Room room = mapper.selectByRoomPrice(id);
        sqlSession.commit();
        sqlSession.close();
        return room;
    }

    /**
     * 通过id改变房间状态
     *
     * @return
     */
    public Boolean alterRoomStatus(int id,int status) {
        //2.获取sqlSession
        SqlSession sqlSession = factory.openSession();
        //3.获取BrandMapper
        HouseInfoMapper mapper = sqlSession.getMapper(HouseInfoMapper.class);
        //4.调用方法
        boolean flag = mapper.alterRoomStatus(id,status);
        sqlSession.commit();
        sqlSession.close();
        return flag;
    }

}
